package com.itbuka.vip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.itbuka.vip.domain.VipFunds;
import com.itbuka.vip.mapper.VipFundsMapper;
import com.itbuka.vip.service.VipFundsService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


import java.util.List;

/**
 * @author ld
 * @description 针对表【vip_funds】的数据库操作Service实现
 * @createDate 2024-07-29 16:57:25
 */
@Service
public class VipFundsServiceImpl implements VipFundsService {
    @Autowired
    private VipFundsMapper vipFundsMapper;

    @Override
    public List<VipFunds> selectAll() {
        LambdaQueryWrapper<VipFunds> lqw = new LambdaQueryWrapper<>();
        lqw.eq(VipFunds::getIsDelete, 0);
        return vipFundsMapper.selectList(lqw);
    }

    @Override
    public List<VipFunds> selectList(VipFunds vipFunds) {
        LambdaQueryWrapper<VipFunds> lqw = this.lqw(vipFunds);
        return vipFundsMapper.selectList(lqw);
    }

    @Override
    public Integer insert(VipFunds vipFunds) {
        return vipFundsMapper.insert(vipFunds);
    }

    @Override
    @Transactional
    public Integer delete(String ids) {
        try {
            String[] split = ids.split(",");
            for (String id : split) {
                VipFunds vipFunds = new VipFunds();
                vipFunds.setId(Long.parseLong(id));
                vipFunds.setIsDelete(1);
                vipFundsMapper.updateById(vipFunds);
            }
            return 1;
        } catch (Exception e) {
            return -1;
        }
    }

    @Override
    public Integer update(VipFunds vipFunds) {
        return vipFundsMapper.updateById(vipFunds);
    }

    @Override
    public Page<VipFunds> pageAll(Integer page, Integer size) {
        PageHelper.startPage(page, size);
        return (Page<VipFunds>) this.selectAll();
    }

    @Override
    public Page<VipFunds> pageList(VipFunds vipFunds, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        return (Page<VipFunds>) this.selectList(vipFunds);
    }

    public LambdaQueryWrapper<VipFunds> lqw(VipFunds vipFunds) {
        LambdaQueryWrapper<VipFunds> lqw = new LambdaQueryWrapper<>();
        if (vipFunds.getId() != null) {
            lqw.eq(VipFunds::getId, vipFunds.getId());
        }
        if (vipFunds.getVipName() != null) {
            lqw.eq(VipFunds::getVipName, vipFunds.getVipName());
        }
        if (vipFunds.getChangeMoney() != null) {
            lqw.eq(VipFunds::getChangeMoney, vipFunds.getChangeMoney());
        }
        if (vipFunds.getChangeTime() != null) {
            lqw.eq(VipFunds::getChangeTime, vipFunds.getChangeTime());
        }
        if (vipFunds.getWorkType() != null) {
            lqw.eq(VipFunds::getWorkType, vipFunds.getWorkType());
        }
        if (vipFunds.getDetail() != null) {
            lqw.eq(VipFunds::getDetail, vipFunds.getDetail());
        }
        if (vipFunds.getIsDelete() != null) {
            lqw.eq(VipFunds::getIsDelete, vipFunds.getIsDelete());
        }
        if (vipFunds.getCreateTime() != null) {
            lqw.eq(VipFunds::getCreateTime, vipFunds.getCreateTime());
        }
        if (vipFunds.getUpdateTime() != null) {
            lqw.eq(VipFunds::getUpdateTime, vipFunds.getUpdateTime());
        }
        return lqw;
    }
}




